package com.cn.designpatterns.ex.concrete.adapter;

import com.cn.designpatterns.ex.concrete.adapter.play.AviPlay;
import com.cn.designpatterns.ex.concrete.adapter.play.Mp3Play;
import com.cn.designpatterns.ex.concrete.adapter.play.Mp4Play;

import java.util.Objects;

/**
 * @author zhangyi
 * @date 2018/12/25 15:34
 */
public class MediaPlayAdapter implements MediaPlay{

    AdvancedMediaPlay advancedMediaPlay;

    /**
     * 根据类型选择不同的执行方法
     *
     * @param type
     */
    @Override
    public void play(String type) {
        if(Objects.nonNull(type)){
            switch (type){
                case "mp3":
                    advancedMediaPlay = new Mp3Play();
                    advancedMediaPlay.mp3Play();
                    break;
                case "mp4":
                    advancedMediaPlay = new Mp4Play();
                    advancedMediaPlay.mp4Play();
                    break;
                case "avi":
                    advancedMediaPlay = new AviPlay();
                    advancedMediaPlay.aviPlay();
                    break;
                    default:
                        System.out.println("Not Support!!!");
                        break;
            }
        }
    }
}
